package cn.yx.framework.view;

import java.util.List;

public class ApiPage<E> extends ApiResult<List<E>> {
    public static final int PAGE_SIZE = 10;
    private int index;
    private int size;
    private int total;
    private boolean next;
    private boolean prev;
    private int page;

    public ApiPage() {
    }

    public ApiPage(int pageIndex, List<E> list) {
        super(list);
        this.index = pageIndex < 0?1:pageIndex;
        this.size = 10;
        int len = list.size();
        this.total = len;
        this.page = len % this.size == 0?len / this.size:len / this.size + 1;
        if(pageIndex > 1 && pageIndex <= this.page) {
            this.prev = true;
        }

        if(pageIndex < this.page) {
            this.next = true;
        }

    }

    public ApiPage(int pageIndex, int pageSize, List<E> list) {
        super(list);
        this.index = pageIndex < 0?1:pageIndex;
        this.size = pageSize < 0?10:(pageSize > 1000?10:pageSize);
        int len = list.size();
        this.total = len;
        this.page = len % this.size == 0?len / this.size:len / this.size + 1;
        if(pageIndex > 1 && pageIndex <= this.page) {
            this.prev = true;
        }

        if(pageIndex < this.page) {
            this.next = true;
        }

    }

    public ApiPage(String msg) {
        super(msg);
    }

    public int getIndex() {
        return this.index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getSize() {
        return this.size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public boolean isNext() {
        return this.next;
    }

    public void setNext(boolean next) {
        this.next = next;
    }

    public boolean isPrev() {
        return this.prev;
    }

    public void setPrev(boolean prev) {
        this.prev = prev;
    }

    public int getTotal() {
        return this.total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getPage() {
        return this.page;
    }

    public void setPage(int page) {
        this.page = page;
    }
}
